Imports System.IO
Imports System.Data.SqlClient


Class MySqlTableProcessor
    Inherits TableProcessor
    Dim cnx As SqlConnection
    Dim cmd As SqlCommand

    Public Overrides Sub Initialize()
        Dim cnxsb As New SqlConnectionStringBuilder()
        'cnxsb.Server = "remote-mysql4.servage.net"
        'cnxsb.Database = "asindo"
        'cnxsb.UserID = "asindo"
        'cnxsb.Password = "S0brepa6789"
        cnxsb.DataSource = "localhost"
        cnxsb.InitialCatalog = "asindo"
        cnxsb.UserID = "root"
        cnxsb.Password = "s0brepa6"

        cnx = New SqlConnection(cnxsb.ToString)
        cmd = New SqlCommand()
        cmd.Connection = cnx
        cnx.Open()
    End Sub

    Public Overrides Sub Process(ByVal xmlOrigen As FileInfo, ByVal ti As TableInfo)
        Console.WriteLine("Escribiendo " & ti.Name)

        Dim tw As TextWriter


        tw = New StringWriter()
        ti.WriteDrop(tw)
        cmd.CommandText = tw.ToString
        cmd.ExecuteNonQuery()
        tw.Close()

        tw = New StringWriter()
        ti.WriteCreate(tw)
        cmd.CommandText = tw.ToString
        cmd.ExecuteNonQuery()
        tw.Close()

        Dim max As Integer = 0
        Dim l = ti.GetInserts
        For Each ins In l
            max = Math.Max(max, ins.Sql.Length)
            cmd.CommandText = ins.Sql

            cmd.ExecuteNonQuery()
        Next
    End Sub

    Public Overrides Sub Finish()
        cnx.Close()
    End Sub

End Class
